package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-01
 * Time: 9:42
 */
public class ReturnOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的图书名:>");
        String name = scanner.nextLine();
        int currentSize = bookList.getUseSize();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                if(book.isBorrowed() == false){
                    System.out.println("此书未借出，无法归还！！！！");
                    return;
                }
                book.setBorrowed(false);
                System.out.println("归还成功！！！");
                System.out.println(book);
                return;
            }
        }
        System.out.println("查无此书！！！");
        //System.out.println("归还图书！！！");
    }
}
